<?php

class Privacy_policy extends Controller {

	function Privacy_policy()
	{
        parent::Controller();    
        if(!admin_session_check()) redirect('admin/login');
        if(!is_allowed("all")) show_404();
        $this->load->model('pageheadersmodel');  
        $this->load->library("form_validation");       
    }     
    
    function index()
    {
        $data["response"] = get_response();  

        $data["item"] = $this->pageheadersmodel->admin_get_item(PRIVACY_POLICY_ID); 
        if(empty($data["item"])) show_404();

        $this->_process_form();

        $data["action"] = "update";
        $data["token"] = generate_token("pageheaders",720);

        $this->load->view('admin/default/head');  
        $this->load->view('admin/default/header', array('selected'=>'pages'));  
        $this->load->view("admin/default/nav_pages", array('selected' => 'privacy_policy'));       
        $this->load->view('admin/privacypolicy/privacypolicy_form', $data);   
        $this->load->view('admin/default/footer');   

    }
      
	   
	/*
    function add()
    {	
        $data = array(
                "id_Pageheaders" => PRIVACY_POLICY_ID,
                "Title_Pageheaders" => "Privacy Policy",
                "Introduction_Pageheaders" => "xxx",
                "Description_Pageheaders" => "xxx"
        ); 
	
		$this->pageheadersmodel->admin_insert($data);
        $this->index();   

    }  
	*/          

    function preview($id = NULL)
    {

        if($this->input->post("submit_action") === FALSE){

            $data["item"] = $this->pageheadersmodel->admin_get_item($id, "id_Pageheaders as id, Title_Pageheaders as title, Introduction_Pageheaders as intro, Description_Pageheaders as description"); 
            if (empty($data["item"])) show_404();             

            $data["action"] = "view";

        } else {

            $data["item"] = array(
                'id' => $this->input->post("id", TRUE),       
                'intro' => $this->input->post("introduction", TRUE),
                'description' => $this->input->post("description", TRUE) );

            $item = $this->pageheadersmodel->admin_get_item($data["item"]["id"], "Title_Pageheaders as title"); 
            $data["item"]["title"] = $item["title"];

            $data["action"] = "preview";

        }

        $data["controller"] = "page_headers";

        $this->load->model('glossarymodel');
        $this->load->view('admin/previews/preview_privacypolicy_template', $data);   

    }
    function _process_form()
    {        
        if($this->input->post("submit_action") !== FALSE){

            if ($this->_validate_form()) {

                if (validate_token("pageheaders",$this->input->post("token",TRUE))){

                    $data = array(
                        'Introduction_Pageheaders' => $this->input->post("introduction"),
                        'Description_Pageheaders' => $this->input->post("description")
                    );

                    switch($this->input->post("submit_action")){    

                        case 'update':

                            $this->pageheadersmodel->admin_update($this->input->post("id"), $data);
                            $item = $this->pageheadersmodel->admin_get_item($this->input->post("id"), "Title_Pageheaders"); 
                            set_response('success','The header for <i>'.$item["Title_Pageheaders"].'</i> was updated. <a href="'.site_url("admin/page_headers/preview/".$this->input->post("id")).'" rel="view">Click to view</a>');

                        break;        

                    }

                    redirect("admin/privacy_policy");

                }
            }   
        }
    }

    private function _validate_form(){
        
        $config[] = array();

            $config[] = array( 
                         'field'   => 'introduction',
                         'label'   => 'Introduction',
                         'rules'   => 'trim|xss_clean'
                        );
             $config[] = array(
                         'field'   => 'description',
                         'label'   => 'Description',
                         'rules'   => 'trim|xss_clean'
                        );
        
                                                 
        $this->form_validation->set_rules($config);       
        $this->form_validation->set_error_delimiters('<span class="error">', '</span>');
        
        if ($this->form_validation->run($this) == FALSE){
            return FALSE;
        }else
            return TRUE;

    }

}

/* End of file welcome.php */
/* Location: ./system/application/controllers/welcome.php */